package com.artevivo.managedBeans;

import java.io.Serializable;

import javax.annotation.Resource;
import javax.faces.bean.RequestScoped;

import org.springframework.stereotype.Controller;

import com.artevivo.entidades.Anyo;
import com.artevivo.entidades.Cliente;
import com.artevivo.services.MatriculaService;

@Controller(value = "matriculaMB")
@RequestScoped
public class MatriculaMB implements Serializable {

    private static final long serialVersionUID = 4178986702876488918L;

    @Resource
    private MatriculaService matriculaService;

    @Resource
    private ClienteMB clienteMB;

    @Resource
    private SessionManagedBean sessionMB;

    public String nuevaMatricula() {

        String res = "FALLO";
        Cliente cliente = clienteMB.guardarCliente();
        Anyo anyo = sessionMB.getSelectedAnyo();

        if (cliente != null) {
            try {
                sessionMB.setSelectedMatricula(matriculaService.altaNueva(cliente, anyo));
                res = "consultar ficha";
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return res;
    }
}